package com.ylbh.modules.member.controller;

import com.ylbh.common.exception.NormalException;
import com.ylbh.common.pojo.member.vo.ConsumerVO;
import com.ylbh.common.pojo.member.dto.select.ConsumerSelectDTO;
import com.ylbh.common.pojo.member.vo.InviteMembersVO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.member.service.ConsumerService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 *
 *消费者数据
 * @author mgh
 * @date 2019-04-17 10:30:39
 */
@RestController
@RequestMapping("member/consumer")
public class ConsumerController {
    @Autowired
    private ConsumerService consumerService;

    /**
     * 消费者数据列表
     */
    @RequestMapping("/queryConsumerList")
    @RequiresPermissions("member:consumer:queryConsumerList")
    public CommonResult<PageUtils> list(ConsumerSelectDTO params){
        PageUtils page = consumerService.queryPage(params);
        return Ref.ok(page);
    }

    @ApiOperation("会员邀请详情")
    @RequestMapping("/getInviteMembersDetailsById/{recommendId}")
    public CommonResult<InviteMembersVO> getInviteMembersDetailsById(@PathVariable String recommendId){
        InviteMembersVO vo = consumerService.getInviteMembersDetailsById(recommendId);
        return Ref.ok(vo);
    }

    /**
     * 信息
     */
    @RequestMapping("/getConsumerById/{playerId}")
    @RequiresPermissions("member:consumer:getConsumerById")
    public CommonResult<ConsumerVO> getConsumerById(@PathVariable("playerId") String playerId){
        ConsumerVO consumerServiceById = consumerService.getById(playerId);

        return Ref.ok(consumerServiceById);
    }

    @GetMapping("acc")
    public CommonResult acc(HttpServletResponse response) throws NormalException {
        consumerService.selectAcc(response);
        return Ref.ok();
    }

    @ApiOperation("导出邀请记录")
    @RequestMapping("exportInvitationRecordExcel")
    public CommonResult exportInvitationRecordExcel(HttpServletRequest request, HttpServletResponse response) throws NormalException {
        consumerService.exportInvitationRecordExcel(request, response);
        return Ref.ok();
    }
}
